<template>
  <div class="login-form">
    <div class="forms">
      <div class="title">煜成购后台管理系统</div>
      <div class="desc">店铺端</div>
      <el-form ref="form" :model="form" :rules="rules" class="form">
        <el-form-item prop="userName" label="">
          <el-input
            v-model="form.userName"
            placeholder="用户名"
            prefix-icon="el-icon-user"
            clearable
          />
        </el-form-item>
        <el-form-item prop="pwd" label="">
          <el-input
            type="password"
            v-model="form.pwd"
            placeholder="密码"
            prefix-icon="el-icon-lock"
            clearable
          />
        </el-form-item>
        <el-form-item :style="{ marginBottom: '0px' }">
          <el-button
            type="primary"
            :loading="loading"
            :style="{
              width: '100%',
              marginTop: '5px',
              backgroundColor: '#4076e3',
              borderColor: '#4076e3',
            }"
            @click="handleLogin"
            block
            >登录</el-button
          >
        </el-form-item>
      </el-form>
    </div>
    <div class="copyright">
      系统推荐浏览器：360浏览器(极速模式)、IE10.0及以上最低分辨率：1366*768
      最佳显示效果：1920*1080
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      form: {
        userName: "",
        pwd: "",
      },
      loading: false,
      rules: {
        userName: [
          {
            required: true,
            message: "请输入用户名",
            trigger: "blur",
          },
        ],
        pwd: [
          {
            required: true,
            message: "请输入密码",
            trigger: "blur",
          },
        ],
      },
    };
  },
  methods: {
    handleLogin() {
      const form = this.form;
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (form.userName !== "admin" || form.pwd !== "123456") {
            this.$message.error("用户名或密码错误");
          } else {
            localStorage.dz_token = "admin";
            this.$router.push("/dashboard");
          }
        }
      });
    },
  },
};
</script>
<style lang="scss" scoped>
.login-form {
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background-color: #f2f2f2;
  .forms {
    padding: 20px;
    width: 320px;
    border-radius: 5px;
    .title {
      text-align: center;
      font-size: 30px;
      padding-bottom: 15px;
    }
    .desc {
      text-align: center;
      color: #999;
      font-size: 16px;
      padding-bottom: 30px;
    }
  }
}
.copyright {
  color: #999;
  text-align: center;
  line-height: 2;
  padding: 30px 0;
}
</style>
